// Created by 王肖肖 on 2021/8/29 09:46
#include <iostream>
#include <vector>

using namespace std;

/**
 * 执行用时：4 ms, 在所有 C++ 提交中击败了76.28%的用户
 * 内存消耗：8.3 MB, 在所有 C++ 提交中击败了11.86%的用户
 */
class Solution {
public:
    int sumOddLengthSubarrays(vector<int>& arr) {
        int n = arr.size();
        vector<int> sum(n + 1);
        for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + arr[i - 1];

        int res = 0;
        for (int len = 1; len <= n; len += 2)
            for (int i = 1; i + len - 1 <= n; i++) {
                int j = i + len - 1;
                res += sum[j] - sum[i - 1];
            }
        return res;
    }
};

int main() {

    vector<int> nums = {1, 4, 2, 5, 3};
    cout << Solution().sumOddLengthSubarrays(nums) << endl;

    return 0;
}
